package com.decent.ejfadmin.report.service.impl;

import com.decent.ejfadmin.report.dao.CollectCardApiStockReportDao;
import com.decent.ejfadmin.report.response.DouLeFaceValueTotal;
import com.decent.ejfadmin.report.response.DouLeProductTypeTotal;
import com.decent.ejfadmin.report.response.DouLeProvinceTotal;
import com.decent.ejfadmin.report.service.CollectCardApiStockReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.List;

/**
 * 给易服务统计的接口
 *
 * @author weicx
 * @date 2019/03/12
 */
@Service
public class CollectCardApiStockReportServiceImpl implements CollectCardApiStockReportService {
    @Autowired
    private CollectCardApiStockReportDao collectCardApiStockReportDao;

    /**
     * 收卡卡密库存统计
     *
     * @return 总数
     */
    @Override
    public List<DouLeProductTypeTotal> collectCardStockReport() {
        return collectCardApiStockReportDao.collectCardStockReport();
    }

    /**
     * 收卡卡密库存面值省份统计
     *
     * @param productType 运营商
     * @return
     */
    @Override
    public List<DouLeProvinceTotal> collectCardStockPricePage(Integer productType) throws UnsupportedEncodingException {
        List<DouLeProvinceTotal> douLeProvinceTotalList=collectCardApiStockReportDao.collectCardStockPricePage(productType);
        for (DouLeProvinceTotal douLeProvinceTotal:douLeProvinceTotalList){
            douLeProvinceTotal.setProvince(URLEncoder.encode(URLEncoder.encode(douLeProvinceTotal.getProvince(),"utf-8"),"utf-8"));
        }
        return douLeProvinceTotalList;
    }

    /**
     * 收卡卡密库存折扣省份统计
     *
     * @param productType 运营商
     * @param province    省份
     * @param faceValue   面值
     * @return
     */
    @Override
    public List<DouLeFaceValueTotal> collectCardPriceReport(Integer productType, String province, Integer faceValue) throws UnsupportedEncodingException {
        String decodeProvince= URLDecoder.decode(province,"utf-8");
        return collectCardApiStockReportDao.collectCardPriceReport(productType,decodeProvince,faceValue);
    }
}
